import requests

# request_url = "http://www.baidu.com"
# resp = requests.get(url=request_url)
# print(resp.status_code)
# print(resp.text)
# print("\n")

# req_url ="http://hmshop-test.itheima.net/Home/Goods/search.html"
# req_params = {"q": "iphone"}
# resp = requests.get(url=req_url,params=req_params)
# print(resp.status_code)
# print(resp.text)

# req_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
# req_data = {"username": "13800000002", "password": "123456", "verify_code": "8888"}
# resp_1 = requests.post(url=req_url, data=req_data) #data传递表单数据
# print(resp_1.status_code)
# print(resp_1.text)
# print(resp_1.json())

# req_url = "http://ihrm2-test.itheima.net/api/sys/login"
# req_json = {"mobile": "13800000002", "password": "888itcast.CN764%..."}
# resp_1 = requests.post(url=req_url, json=req_json)
# print(resp_1.status_code)
# print(resp_1.json())
# print(type(resp_1.json()))
#
# #输出员工列表
# req_url = "http://ihrm2-test.itheima.net/api/sys/user"
# req_params = {"page": 1, "size": 10}
# token = resp_1.json()["data"] #令牌
# print(token)
# print(type(token))
# req_head = {"Authorization": "Bearer " + token}
# resp_2 = requests.get(url=req_url, params=req_params , headers=req_head)
# total_sum = resp_2.json()["data"]["total"]
# req_params = {"page": 1, "size": total_sum}
# print(resp_2.status_code)
# print(resp_2.json())
# print(resp_2.json()["data"]["total"])
# # id_1 = resp_2.json()["data"]["rows"][5]["id"]
# print(resp_2.json()["data"]["rows"][5]["id"])
# print(resp_2.json()["data"]["rows"][5]["username"])



# req_url = "http://ihrm2-test.itheima.net/api/sys/user/1075383133106425856" #改amy
# req_json = {"username": "小小桥", "password": "32112311"}
# req_head = {"Authorization": "Bearer " + token}
# req = requests.put(url=req_url, json=req_json, headers=req_head)
# print(req.status_code)
# print(req.text)
# print(req.json())
# print(f"结果为-id:{resp_2.json()['data']['rows'][5]['id']},name:{resp_2.json()['data']['rows'][5]['username']}")  #前面再输出一遍员工列表



# req_url = "http://ihrm2-test.itheima.net/api/sys/user/1235396819959627776"
# req_head = {"Authorization": "Bearer 8e02f942-84da-43cd-82e4-7cc8d08a6e71"}
# req = requests.delete(url=req_url, headers=req_head)
# print(req.status_code)
# print(req.text)
# print(req.json())

#token
login_url = "http://ihrm2-test.itheima.net/api/sys/login"
login_json = {"mobile": "13800000002", "password": "888itcast.CN764%..."}
req_url = "http://ihrm2-test.itheima.net/api/sys/user/1235396819959627776"

resp_login = requests.post(url=login_url, json=login_json)
print(resp_login.json())
# token_ = "Bearer " + resp_login.json()["data"]
# header_1 = {"Authorization": token_}
# print(header_1["Authorization"])
# resp_search = requests.get(url=req_url, headers=header_1)
# print(resp_search.status_code)
# print(resp_search.json())

#cookie
# code_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify"
# login_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
# login_data = {"username": "13334234412", "password": "123321", "verify_code": "8888"}
# order_url = "http://hmshop-test.itheima.net/Home/Order/order_list.html"
#
# code_resp = requests.get(url=code_url)
# print(code_resp.status_code)
# # print(code_resp.text)
# cookie_ = code_resp.cookies
# print(cookie_,type(cookie_))
# resp_ = requests.post(url=login_url, data=login_data, cookies=cookie_)
# print(resp_.json())
# resp_order = requests.get(url=order_url,cookies=cookie_)
# print(resp_order.status_code)
# print(resp_order.text)

#session
# code_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify"
# login_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
# login_data = {"username": "13334234412", "password": "123321", "verify_code": "8888"}
# order_url = "http://hmshop-test.itheima.net/Home/Order/order_list.html"
# sess = requests.session()
# res_code = sess.get(url=code_url)
# print(res_code.status_code)
# res_login = sess.post(url=login_url, data=login_data)
# print(res_login.status_code)
# print(res_login.json())
# res_order = sess.get(url=order_url)
# print(res_order.status_code)
# print(res_order.text)
# print(res_order.request.headers)
#
# #查看响应信息和请求信息
# url_1 = "http://www.baidu.com"
# resp = requests.get(url_1)
# print(resp.status_code)
# print(resp.text)
# print(resp.content)
# # print(resp.json())
# print(resp.encoding)
# resp.encoding = 'utf-8'
# print(resp.encoding)
# print(resp.url)
# print(resp.cookies)
# print("响应头")
# print(resp.headers) #响应头
#
# print(resp.request.headers) #请求头
# print(resp.request.method) #请求方法
# print(resp.request.body) #请求体